package com.bbz.core.set;

public class TreeSetModel implements Comparable<Object> {

	private String name;
	private int age;
	private String gender;

	public TreeSetModel() {

	}

	public TreeSetModel(String name, int age, String gender) {

		this.name = name;
		this.age = age;
		this.gender = gender;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	@Override
	public int hashCode() {
		return name.hashCode() + age * 37;
	}

	public boolean equals(Object obj) {
		System.err.println(this + "equals :" + obj);
		if (!(obj instanceof TreeSetModel)) {
			return false;
		}
		TreeSetModel p = (TreeSetModel) obj;
		return this.name.equals(p.name) && this.age == p.age;

	}

	public String toString() {
		return "TreeSetModel [name=" + name + ", age=" + age + ", gender=" + gender + "]";
	}

	@Override
	public int compareTo(Object obj) {

		TreeSetModel p = (TreeSetModel) obj;
		System.out.println(this + " compareTo:" + p);
		if (this.age > p.age) {
			return 1;
		}
		if (this.age < p.age) {
			return -1;
		}
		return this.name.compareTo(p.name);
	}
}
